package com.wz.project.bas.customerGroup.controller;

import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.framework.web.page.TableDataInfo;
import com.wz.project.bas.customerGroup.domain.BasCustomerGroup;
import com.wz.project.bas.customerGroup.service.IBasCustomerGroupService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客户组Controller
 * 
 * @author wz
 * @date 2022-02-10
 */
@Controller
@RequestMapping("/bas/customerGroup")
public class BasCustomerGroupController extends BaseController
{
    private String prefix = "bas/customerGroup";

    @Autowired
    private IBasCustomerGroupService basCustomerGroupService;

//    @RequiresPermissions("bas:customerGroup:view")
    @GetMapping()
    public String customerGroup()
    {
        return prefix + "/customerGroup";
    }

    /**
     * 查询客户组列表
     */
//    @RequiresPermissions("bas:customerGroup:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BasCustomerGroup basCustomerGroup)
    {
        startPage();
        List<BasCustomerGroup> list = basCustomerGroupService.selectBasCustomerGroupList(basCustomerGroup);
        return getDataTable(list);
    }

    /**
     * 导出客户组列表
     */
//    @RequiresPermissions("bas:customerGroup:export")
    @Log(title = "客户组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BasCustomerGroup basCustomerGroup)
    {
        List<BasCustomerGroup> list = basCustomerGroupService.selectBasCustomerGroupList(basCustomerGroup);
        ExcelUtil<BasCustomerGroup> util = new ExcelUtil<BasCustomerGroup>(BasCustomerGroup.class);
        return util.exportExcel(list, "customerGroup");
    }

    /**
     * 新增客户组
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存客户组
     */
    @RequiresPermissions("bas:customerGroup:add")
    @Log(title = "客户组", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BasCustomerGroup basCustomerGroup)
    {
        return toAjax(basCustomerGroupService.insertBasCustomerGroup(basCustomerGroup));
    }

    /**
     * 修改客户组
     */
    @GetMapping("/edit/{customerGroupNo}")
    public String edit(@PathVariable("customerGroupNo") String customerGroupNo, ModelMap mmap)
    {
        BasCustomerGroup basCustomerGroup = basCustomerGroupService.selectBasCustomerGroupById(customerGroupNo);
        mmap.put("basCustomerGroup", basCustomerGroup);
        return prefix + "/edit";
    }

    /**
     * 修改保存客户组
     */
    @RequiresPermissions("bas:customerGroup:edit")
    @Log(title = "客户组", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BasCustomerGroup basCustomerGroup)
    {
        return toAjax(basCustomerGroupService.updateBasCustomerGroup(basCustomerGroup));
    }

    /**
     * 删除客户组
     */
    @RequiresPermissions("bas:customerGroup:remove")
    @Log(title = "客户组", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(basCustomerGroupService.deleteBasCustomerGroupByIds(ids));
    }
}
